#include "dag.h"
#include "dag_operators.h"
#include "dag_frame_op_factory.h"
#include "dag_threading.h"

#include <map>
#include <string>
#include <iostream>

using namespace dag;
using namespace std;

void dag::register_inflator(const char* opId, 
							frame_op_inflate_fp inflateFunc) {
	FrameOpFactory::instance().induct(opId, inflateFunc);
}

FrameOpFactoryImpl::FrameOpFactoryImpl() {
}

void FrameOpFactoryImpl::induct(const string& className, 
							  frame_op_inflate_fp inflatorFunc) {
	ScopedLock sl(m_InflatorsMutex);
	m_Inflators[className] = inflatorFunc;
}

auto_ptr<FrameOperator> FrameOpFactoryImpl::inflate(const string& frameOperatorID,
													istream& bStream) {
	register_internal_inflators();
	ScopedLock sl(m_InflatorsMutex);	
	if (m_Inflators.count(frameOperatorID) == 0) {
		throw SerialError(string("unregistered frame operator id - ") + 
						  frameOperatorID);
	}
	
	return m_Inflators[frameOperatorID](bStream);
}


